/*
 * Created on Jul 5, 2004
 *
 */
/*
 * Created on Feb 8, 2004
 *
 * To change the template for this generated file go to
 * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
 */
package littlecyberwar.ui;

import java.util.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;


import littlecyberwar.model.*;
import littlecyberwar.ui.*;
import littlecyberwar.util.*;
import littlecyberwar.tool.MouseHandler;
/**
 * @author Milton  Soong
 *
 * To change the template for this generated type comment go to
 * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
 */
public class RemoveAction extends LCWAction { 
	private static RemoveAction instance = null;
	
	private RemoveToTrayDialog removeDiag = null;
	private InternalCmdFacade mod;
	
  PlayingBoardPanel pbp;
   public RemoveAction(String text, 
					 ImageIcon icon,
					 String desc, 
					 KeyStroke k, 
					 MainFrame fr, 
					 PlayingBoardPanel pbpIn, 
					 String mouseHandlerClassName) {
		   super(text, icon, desc, k, fr);
		   pbp = pbpIn;
		   mod = fr.getIcmd();
		   instance = this;
		
		   // The class for the action is loaded here
		   MouseHandler	handler=null;	
		   if ( mouseHandlerClassName != null ) {
			  ClassLoader loader = this.getClass().getClassLoader();
			  try {
				Class cl = loader.loadClass("littlecyberwar.tool." + mouseHandlerClassName);
			handler = (MouseHandler)cl.newInstance();
		
		  } catch ( Exception ex ) {
			ex.printStackTrace();
		  }
		  if ( handler != null ) {
		   handler.setBoardPanel(pbp);
		   putValue(ModeAction.LCW_MOUSEHANDLER, handler);	
		   MainFrame mf = (MainFrame)fr;
		   ProfileCardPanel pp = mf.getProfilePanel();
		   CardLayout ppc = mf.getProfilePanelCard();
		   handler.setProfilePanel(pp);
		   handler.setProfilePanelCard(ppc);
		  }
		}		
   }
	
  public void actionPerformed(ActionEvent e) {
  	if ( removeDiag == null ) {
  		// the remove dialog has not been set yet
		JOptionPane.showMessageDialog(frame,
			"No Trays have been defined yet. Please open a scenario file first.");
  	} else {
		Dimension dlgSize = removeDiag.getPreferredSize();
		Dimension frmSize = frame.getSize();
		Point loc = frame.getLocation();
		removeDiag.setLocation((frmSize.width - dlgSize.width) / 2 + loc.x, (frmSize.height - dlgSize.height) / 2 + loc.y);	
		removeDiag.show();
  	}
  	return;
  }
  
  public void setRemoveDialog(RemoveToTrayDialog diag) {
  		removeDiag = diag;
  }
  
  public static RemoveAction getInstance() {
  	return ( instance );
  }
}

